<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>画线</title>
  <style>
    body {
      display: flex;
      justify-content: center;
      align-items: center;
    }
    .box {
      position: relative;
      width: 500px;
      height: 500px;
      border: 1px solid red;
    }
  </style>
</head>
<body>
  <div class="box"></div>

  <script type="text/javascript" src="../js/three.js"></script>
  <script type="module" src="../js/stats.module.js"></script>
  <script type="module">
    import { createBaseObj, getRanderPoint, getStats } from '../js/myThree.js'

    const oBox = document.getElementsByClassName('box')[0]
    const oBoxWidth = oBox.clientWidth
    const oBoxHeight = oBox.clientHeight

    const { scene, camera, renderer} = createBaseObj()
    const state = getStats()

    const initBase = () => {
      renderer.setSize(oBoxWidth, oBoxHeight)
      oBox.appendChild(renderer.domElement)
      oBox.appendChild(state.domElement)

      const axesHelper = new THREE.AxesHelper(1000)
      scene.add( axesHelper)

      camera.position.set(150, 150, 150)
      camera.lookAt(0, 0, 0)
    }

    const getMaterial = () => {
      return new THREE.LineBasicMaterial({ color: 0xfff630 })
    }

    const points = []
    const getGeometry = () => {
      points.push(new THREE.Vector3(-10, 0, 0))
      points.push(new THREE.Vector3(0, 10, 0))
      points.push(new THREE.Vector3(10, 1, 0))

      return new THREE.BufferGeometry().setFromPoints( points )
    }

    const drawLine = () => {
      const material = getMaterial()
      const geometry = getGeometry()

      return new THREE.LineSegments(geometry, material)
    }

    const doSth = () => {
      scene.add(drawLine())
    }

    let controls
    function initControls() {
      controls = new THREE.OrbitControls(camera, renderer.domElement)
      controls.enableZoom = false
      controls.minPolarAngle - Math.PI / 2.5
      controls.maxPolarAngle - Math.PI / 2.5
    }

    const animation = () => {
      requestAnimationFrame(animation)
      doSth()
      state.update()
      renderer.render(scene, camera)
    }

    initBase()
    animation()
  </script>
</body>
</html>